package com.harlaus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.harlaus.entity.CommonResult;
import com.harlaus.entity.Payment;
import com.harlaus.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private Integer port;

    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment){
        int insert = paymentService.getBaseMapper().insert(payment);
        if(insert > 0){
            return new CommonResult(200,"插入成功,端口" + port,payment);
        }else {
            return new CommonResult(500,"插入失败,端口" + port,null);
        }
    }

    @GetMapping("/query/{id}")
    @ResponseBody
    public CommonResult query(@PathVariable Long id){
        Integer count = paymentService.getBaseMapper().selectCount(new QueryWrapper<Payment>().eq("id", id));
        if(count > 0){
            Payment payment = paymentService.getBaseMapper().selectOne(new QueryWrapper<Payment>().eq("id", id));
            return new CommonResult(200, "查询成功,端口" + port, payment);
        }else {
            return new CommonResult(500,"查询失败,端口" + port,null);
        }
    }
}
